//
//  ViewController.m
//  09—UITableViewController
//
//  Created by 冀永金 on 16/7/26.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *nameArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.nameArray = [NSMutableArray arrayWithArray:@[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"]];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool"];
//    UIView *viewOf = [[UIView alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200)];
//    [self.view addSubview:viewOf];
//    viewOf.backgroundColor = [UIColor redColor];
    // 注意：UITableViewController中self.view是tableview
    NSLog(@"%@",self.view);
    //1.系统刷新控件 UIRefreshControl
    //注意：UIRefreshControl 有自己的init的方法
    self.refreshControl = [[UIRefreshControl alloc]init];
    //2. UIRefreshControl继承于 UIContorl
    // 可以绑定事件
    // 系统API注释中说明触发事件的枚举值UIControlEventValueChanged
    [self.refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
        // Do any additional setup after loading the view, typically from a nib.
}
// 刷新方法
- (void)handleRefresh:(UIRefreshControl *)refresh {
    // 延时操作
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.refreshControl endRefreshing];
    });
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.nameArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    cell.textLabel.text = _nameArray[indexPath.row];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
